package com.quanfaqiang.demo1.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quanfaqiang.demo1.anno.AddLog;
import com.quanfaqiang.demo1.anno.DeleteLog;
import com.quanfaqiang.demo1.anno.UpdateLog;
import com.quanfaqiang.demo1.pojo.Result;
import com.quanfaqiang.demo1.pojo.Task;
import com.quanfaqiang.demo1.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;

    @GetMapping("/SelectAll")
    public Result SelectAll(int currentPage, int pageSize) {
        Page<Task> TaskPage = taskService.SelectAll(currentPage, pageSize);
        return Result.success(TaskPage);
    }

    @DeleteLog
    @DeleteMapping("/deleteId/{id}")
    public Result<String> DeleteId(@PathVariable Integer id) {
        taskService.DeleteId(id);
        return Result.success("删除成功");
    }

    @DeleteLog
    @DeleteMapping("/deleteMore/{ids}")
    public Result deleteIds(@PathVariable List<Integer> ids) {
        taskService.deleteIds(ids);
        return Result.success("批量删除成功");
    }


    @GetMapping("/selectId")
    public Result SelectId(@RequestParam Integer id) {
        Task task = taskService.SelectId(id);
        return Result.success(task);
    }

    @AddLog
    @PostMapping("/add")
    public Result add(@RequestBody Task task) {
        taskService.Add(task);
        return Result.success("添加成功");
    }

    @UpdateLog
    @PutMapping("/update")
    public Result update(@RequestBody Task task) {
        taskService.update(task);
        return Result.success("修改成功");
    }

    @GetMapping("/selectTaskName")
    public Result selectTaskName(String name,Integer id){
        Boolean flag=taskService.selectTaskName(name,id);
        return Result.success(flag);
    }

    @GetMapping("/selectUuidNumber")
    public Result selectUuidNumber(Integer uuidNumber){
        Task flag=taskService.selectUuidNumber(uuidNumber);
        return Result.success(flag);
    }

    @GetMapping("/serchTask")
    public Result serchTask(Integer uuidNumber,String name ,Integer currentPage, Integer pageSize, String username,Integer number,String content){

        Page<Task> taskPage=taskService.serchTask(uuidNumber,name,currentPage,pageSize,username,number,content);
        return Result.success(taskPage);
    }

    @UpdateLog
    @GetMapping("/updateState")
    public Result updateState(Integer id,boolean state){
        Boolean flag=taskService.updateState(id,state);
        return Result.success(flag);
    }

}
